{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ac933e02",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os \n",
    "\n",
    "\n",
    "from os.path import join, dirname, abspath  \n",
    "from tqdm import tqdm\n",
    "from os.path import exists,join\n",
    "import json\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "edfde34d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eb84102d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "4b8e7300",
   "metadata": {},
   "source": [
    "# refiner json generation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "397b2eea",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "root = '/share/project/cwm/shaocong.xu/exp/Lotus/data/MoGe_submission/submission'\n",
    "\n",
    "\n",
    "import glob\n",
    "imgs_list = glob.glob(join(root, '*/*.npy'))\n",
    "\n",
    "\n",
    "\n",
    "with open(join(dirname(root), 'test.jsonl'),'w') as f :\n",
    "    for line in imgs_list:\n",
    "        f.write(json.dumps({'data_path': line}) + '\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6a48db38",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "45045it [00:00, 162596.51it/s]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "\n",
    "src_jsonl = '/share/project/cwm/shaocong.xu/exp/Lotus/data/XYZ/train_moge.jsonl'\n",
    "\n",
    "\n",
    "from tqdm import tqdm\n",
    "import json\n",
    "\n",
    "def load_jsonl(src_jsonl):\n",
    "    data = []\n",
    "    with open(src_jsonl, 'r') as f:\n",
    "        for line in tqdm(f):\n",
    "            data.append(json.loads(line))\n",
    "    return data\n",
    "\n",
    "\n",
    "src_data = load_jsonl(src_jsonl)\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "edafe056",
   "metadata": {},
   "outputs": [],
   "source": [
    "real_data = []\n",
    "\n",
    "for line in src_data:\n",
    "    if 'real' in line['conditioning_image']:\n",
    "        real_data.append(line)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ce87840f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(45, 45045)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(real_data),len(src_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ae447186",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "\n",
    "\n",
    "def write_jsonl(data, output_file):\n",
    "    with open(output_file, 'w') as f:\n",
    "        for item in data:\n",
    "            f.write(json.dumps(item) + '\\n')\n",
    "\n",
    "\n",
    "\n",
    "write_jsonl(real_data, '/share/project/cwm/shaocong.xu/exp/Lotus/data/XYZ/train_real_moge.jsonl')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
